package com.example.emos.api.task;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import com.example.emos.api.exception.EmosException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;


/**
 * 请假异步线程类
 */
@Component
@Slf4j
public class LeaveWorkflowTask {

    @Async("AsyncTaskExecutor")
    public void deleteLeaveWorkflow(String instanceId,String type,String reason){
        JSONObject json = new JSONObject();
        json.set("instanceId",instanceId);
        json.set("type",type);
        json.set("reason",reason);

        String url = "";
        HttpResponse resp = HttpRequest.post(url).header("Content-type","application/json").body(json.toString()).execute();
        if(resp.getStatus()!=200){
            log.error(resp.body());
            throw new EmosException("请假工作流删除失败");
        }

    }

}
